const { DataTypes } = require('sequelize')
const seq = require('../db/seq')

const Post = seq.define('Post', {
    id: {
        type: DataTypes.UUID,
        defaultValue: DataTypes.UUIDV4, // 自动生成 UUID
        primaryKey: true,
        allowNull: false,
        comment: '帖子ID',
    },
    content: {
        type: DataTypes.TEXT,
        allowNull: false,
        comment: "发表内容",
    },
    contentImage: {
        type: DataTypes.TEXT,
        allowNull: false,
        comment: '图片内容'
    },
    authorId: {
        type: DataTypes.UUID,
        defaultValue: DataTypes.UUIDV4,
        comment: "用户id",
        references: {
            model: 'users', // 关联 User 表
            key: 'user_id',
        },
        onDelete: 'CASCADE', // 删除用户时删除好友关系
    },
    authorName: {
        type: DataTypes.STRING,
        allowNull: false,
        comment: '用户昵称'
    },
    image: {
        type: DataTypes.STRING,
        allowNull: false,
        comment: '用户头像'
    }
})

// Post.sync({ force: true })

module.exports = Post